<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<base href="${base}/" />
<title></title>
<link rel="stylesheet" href="css/pintuer.css">
<link rel="stylesheet" href="css/admin.css">
</head>
<script src="js/jquery-3.5.0.js"></script>
<script src="layer/layer.js"></script>
<script>
	function del(id,name) {
		layer.confirm('您确定删除吗？', {
			btn : [ '确定', '取消' ]
		//按钮
		},function() {
			location.href = "Adminservlet?opr=del&id=" + id+"&name="+name;
		} , function() {
			return;
		})
	}
	
	function toAdd(){
		location.href="admin/admin_add.jsp";
	}
	window.addEventListener("load",function(){
		let error = "${error}";
		if(error!=""){
			layer.alert(error);
		}
		let success = "${success}";
		if(success!=""){
			layer.alert(success);
		}
		
		let xhr = new XMLHttpRequest();
		xhr.open("get","Adminservlet?opr=list");
		xhr.onreadystatechange = function(){
			if(xhr.readyState==4&&xhr.status==200){
				let result = JSON.parse(xhr.responseText);
				let admins = result.data;
				if(admins!=null&&admins.length!=0){
					let num=1;
					for(let admin of admins){
						let tr = document.createElement("tr");
						let count = document.createElement("td");
						count.innerHTML = num++;
						tr.appendChild(count);
						let account = document.createElement("td");
						account.innerHTML = admin.account;
						tr.appendChild(account);
						let role = document.createElement("td");
						role.innerHTML = admin.role;
						tr.appendChild(role);
						let lastloginip = document.createElement("td");
						lastloginip.innerHTML = admin.lastloginip;
						tr.appendChild(lastloginip);
						let lastlogintime = document.createElement("td");
						lastlogintime.innerHTML = admin.lastlogintime;
						tr.appendChild(lastlogintime);
						let status = document.createElement("td");
						status.innerHTML = admin.status;
						tr.appendChild(status);
						document.getElementsByTagName("tbody")[0].appendChild(tr);
						
					}
				}
				
			}
		}
		xhr.send();
	})
	
</script>
<body>
	<form method="post" action="">
		<div class="panel admin-panel">
			<div class="panel-head">
				<strong class="icon-reorder">管理员列表</strong>
			</div>
			<div class="padding border-bottom">
				<button type="button" class="button border-yellow" onclick="toAdd()">
					<span class="icon-plus-square-o"></span>增加管理员
				</button>
			</div>
			<table class="table table-hover text-center">
				<tr>
					<th>序号</th>
					<th>账号名称</th>
					<th>角色</th>
					<th>最后登录时间</th>
					<th>最后登录IP</th>
					<th>状态</th>
				</tr>
<%-- 				<c:forEach items="${admins}" var="admin" varStatus="s"> --%>
<!-- 					<tr> -->
<%-- 						<td>${s.count}</td> --%>
<%-- 						<td>${admin.account}</td> --%>
<%-- 						<td>${admin.role}</td> --%>
<%-- 						<td>${admin.lastlogintime}</td> --%>
<%-- 						<td>${admin.lastloginip}</td> --%>
<%-- 						<td>${admin.status}</td> --%>
<!-- 						<td> -->
<!-- 							<div class="button-group"> -->


<!-- 								<a class="button border-main" -->
<%-- 									href="Adminservlet?opr=initupdate&account=${admin.account}"><span --%>
<!-- 									class="icon-edit"></span> 修改</a> <a class="button border-red" -->
<%-- 									href="javascript:void(0)" onclick="del('${admin.id}','${admin.account}')"><span --%>
<!-- 									class="icon-trash-o"></span> 删除</a> -->
<!-- 							</div> -->
<!-- 						</td> -->
<!-- 					</tr> -->
<%-- 				</c:forEach> --%>
			</table>
		</div>
	</form>
</body>
</html>